package com.corpgovernment.travelstandard.loader;

import com.corpgovernment.travelstandard.entity.db.MbTravelstandCarModel;
import com.corpgovernment.travelstandard.mapper.MbTravelstandCarModelMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jhxue
 * @create 2022-05-12-17:56
 */
@Component
public class MbTravelStandardCarModelLoader {

	@Autowired
	private MbTravelstandCarModelMapper mbTravelstandCarModelMapper;

	/**
	 * 批量保存
	 *
	 * @param entityList
	 * @return
	 */
	public boolean batchSave(List<MbTravelstandCarModel> entityList) {
		if (CollectionUtils.isEmpty(entityList)) {
			return false;
		}
		mbTravelstandCarModelMapper.insertList(entityList);
		return true;
	}

	/**
	 * 根据tsId查询
	 *
	 * @param tsId
	 * @return
	 */
	public List<MbTravelstandCarModel> selectByTsIdAndType(Long tsId, String tsType) {
		if (tsId == null) {
			return new ArrayList<>();
		}
		Example example = new Example(MbTravelstandCarModel.class);
		example.createCriteria()
			   .andEqualTo("tsCarId", tsId)
			   .andEqualTo("tsType", tsType);
		return mbTravelstandCarModelMapper.selectByExample(example);
	}

	/**
	 * 根据tsIds查询
	 *
	 * @param tsIds
	 * @return
	 */
	public List<MbTravelstandCarModel> selectByTsIds(List<Long> tsIds, String tsType) {
		if (CollectionUtils.isEmpty(tsIds)) {
			return new ArrayList<>();
		}
		Example example = new Example(MbTravelstandCarModel.class);
		example.createCriteria()
			   .andIn("tsCarId", tsIds).andEqualTo("tsType", tsType);
		return mbTravelstandCarModelMapper.selectByExample(example);
	}

	/**
	 * 删除职级差标
	 *
	 * @param tsId
	 * @param tsType
	 * @return
	 */
	public boolean deleteByTsIdAndType(Long tsId, String tsType) {
		if (tsId == null || StringUtils.isEmpty(tsType)) {
			return false;
		}
		Example example = new Example(MbTravelstandCarModel.class);
		example.createCriteria()
			   .andEqualTo("tsCarId", tsId)
			   .andEqualTo("tsType", tsType);
		return mbTravelstandCarModelMapper.deleteByExample(example) > 0;
	}
}
